/*
Copyright (c) 2008, Mike Gashler

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef __GHTML_H__
#define __GHTML_H__

class GConstStringHashTable;
struct GHtmlTagHandlerStruct;

// This class is for parsing HTML files. It's designed to be very simple.
// This class might be useful, for example, for building a web-crawler
// or for extracting readable text from a web page.
class GHtml
{
protected:
	const char* m_pDoc;
	int m_nSize;
	int m_nPos;

public:
	GHtml(const char* pDoc, int nSize);
	virtual ~GHtml();

	// You should call this method in a loop until it returns false. It parses a
	// little bit more of the document each time you call it. It returns false
	// if there was nothing more to parse. The various virtual methods are called
	// whenever it finds something interesting.
	bool ParseSomeMore();

	// This method will be called whenever the parser finds a section of display text
	virtual void OnTextChunk(const char* pChunk, int chunkSize) {}

	// This method is called whenever a new tag is found
	virtual void OnTag(const char* pTagName, int tagNameLen) {}

	// This method is called for each parameter in the tag
	virtual void OnTagParam(const char* pTagName, int tagNameLen, const char* pParamName, int paramNameLen, const char* pValue, int valueLen) {}

	// This method is called when an HTML comment (<!--comment-->) is found
	virtual void OnComment(const char* pComment, int len) {}

protected:
	void ParseTag();
};

#endif // __GHTML_H__
